Imports System.io

Friend Class frmSettings

    Private EH As ErrorHandler
    Dim TFH As New TextHandler

    Private Sub frmSettings_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Try

            Dim AL As ArrayList = TFH.ReadFileLinesToArrayList("Settings.ini")

            Try                
                txtDataSource.Text = AL.Item(0)
                txtInitialCat.Text = AL.Item(1)
                txtDBUser.Text = AL.Item(2)
                txtDBPass.Text = AL.Item(3)
            Catch ex As Exception
                'MsgBox(ex.Message)
            End Try

        Catch ex As Exception

            Dim EH As New ErrorHandler
            EH.RecordError(ex)

        End Try

    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

        Try

            Dim Msg As String
            Dim Line As String
            Line = txtDataSource.Text & ", " & txtInitialCat.Text & ", " & txtDBUser.Text & ", " & txtDBPass.Text

            If TFH.WriteLineToFile(Line, "Settings.ini", True) = False Then
                Throw New Exception("Could not save settings.")
            End If

            Msg = "New settings were saved and will be used the next time the application starts.  Do you want to restart now?"

            If MsgBox(Msg, MsgBoxStyle.YesNo, "Settings Saved") = MsgBoxResult.Yes Then
                End
            Else
                Me.Close()
            End If

        Catch ex As Exception

            EH = New ErrorHandler
            EH.RecordError(ex)
            MsgBox("Could not save connection settings.", MsgBoxStyle.Critical, "Settings Error")

        End Try

    End Sub
End Class